package com.ihr360.binlog.datasource;

import com.google.common.collect.ImmutableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JdbcTemplateHolder {
    public final static class TEMPLATE{
        public final static String PAYROLL_JDBCTEMPLATE="payrollJdbcTemplate";
        public final static String SIHF_JDBCTEMPLATE="sihfJdbcTemplate";
    }
    @Qualifier(value = "payrollJdbcTemplate")
    @Autowired
    private JdbcTemplate payrollJdbcTemplate;

    @Qualifier(value = "sihfJdbcTemplate")
    @Autowired
    private JdbcTemplate sihfJdbcTemplate;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<JdbcTemplate> templates(){
        return ImmutableList.of(payrollJdbcTemplate,sihfJdbcTemplate);
    }

    public JdbcTemplate template(String template){
        switch (template){
            case TEMPLATE.PAYROLL_JDBCTEMPLATE:
                return payrollJdbcTemplate;
            case TEMPLATE.SIHF_JDBCTEMPLATE:
                return sihfJdbcTemplate;
        }
        return jdbcTemplate;
    }
}